Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace update functions with a merge function #51

Merged
merged 3 commits into from
Oct 16, 2023

Conversation

zknill
Copy link
Collaborator

@zknill zknill commented Oct 13, 2023

Replace the per-channel-per-event update function mapping with a single merge function. This makes the UpdatesRegistry redundant, as we don't need a class to hold the old mapping: "channel -> eventName -> function"

Update the tests, and rename some update terminology to merge.

Also:

  • Accept the channel name as a constructor argument to the Model.
  • The StreamFactory is now only responsible for creating streams given the
    channel name and the set of default options. It doesn't hold on to the
    references to stream after creating them.

@zknill zknill requested a review from mschristensen October 13, 2023 10:48
@zknill zknill force-pushed the feature/COL-40-replace-update-function-merge-function branch from cdb726f to 99e6914 Compare October 13, 2023 11:20
Replace the per-channel-per-event update function mapping with a single
merge function. This makes the UpdatesRegistry redundant, as we don't
need a class to hold the old mapping:  "channel -> eventName -> function"

Update the tests, and rename some update terminology to merge.

Also:
- accept the channel name as a constructor argument to the Model.

squash
The StreamFactory is now only responsible for creating streams given the
channel name and the set of default options. It doesn't hold on to the
references to stream after creating them.
@zknill zknill force-pushed the feature/COL-40-replace-update-function-merge-function branch from 99e6914 to 2f9adbd Compare October 13, 2023 11:29
Copy link
Collaborator

@mschristensen mschristensen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice LGTM, just some very minor comments

[event: string]: UpdateFunc<T>;
};
};
$merge?: MergeFunc<T>;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can drop the $ prefixes, wdythink? Originally this was inteneded to distinguish between user-defined functions and those exposed on the model, although we're namespacing so we don't really need it.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't have to be in this PR - I have created a ticket to do this separately for all registrations: https://ably.atlassian.net/browse/COL-518

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, good idea 👍

@@ -9,7 +9,7 @@ import { MutationMethods } from './types/mutations.js';

vi.mock('ably/promises');

interface ModelTestContext extends ModelOptions {}
type ModelTestContext = { channelName: string } & ModelOptions;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we just store the channelName on the ModelOptions directly?

src/Model.ts Outdated Show resolved Hide resolved
src/Model.ts Outdated
logger: options.logger,
eventBufferOptions: options.eventBufferOptions,
});
this.stream = this.streamFactory.newStream({ channel: channel });
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can just be { channel }

src/StreamFactory.ts Outdated Show resolved Hide resolved
@zknill zknill requested a review from mschristensen October 16, 2023 10:30
@zknill zknill merged commit 93898ab into main Oct 16, 2023
5 checks passed
@zknill zknill deleted the feature/COL-40-replace-update-function-merge-function branch October 16, 2023 11:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants